using Config;
using Data;
using Data.Bag;
using Map.MapObject.Building;
using MoonFramework.Scripts.Event;
using MoonFramework.Scripts.View.UI;
using MoonFramework.Template;
using Tool;
using Tool.Name;
using UI.Bag;
using UnityEngine;

namespace Bag
{
    public class BagManager : BaseManager<BagManager>
    {
        private UI_ToolBarWindow _toolBarWindow; //快捷栏
        
        public void Init()
        {
            _toolBarWindow = UIManager.Instance.Show<UI_ToolBarWindow>();    
            _toolBarWindow.InitData();
            EventCenter.Instance.SendCommand(EventName.SaveGame, OnGameClose);
        }

        #region 快捷栏(主背包逻辑)
        public void UpdateItemForBuild(BuildConfig buildConfig) => _toolBarWindow.UpdateItemForBuild(buildConfig);
        public int GetItemCount(int itemID) => _toolBarWindow.GetItemCount(itemID);
        public bool AddItemAndCheck(int itemID) => _toolBarWindow.AddItemAndCheck(itemID);
        
        #endregion


        #region 储物箱背包
        public void OnBoxShow(StorageBox storageBox, BagData bagData, Vector2Int size)
        {
            ProjectTool.PlayAudio(PlayerAudioName.Bag);
            UIManager.Instance.Close<UI_StorageBoxWindow>();
            UIManager.Instance.Show<UI_StorageBoxWindow>().Init(storageBox, bagData, size);
        }
        #endregion
        
        private void OnGameClose()
        {
            //保存快捷栏数据
            ArchiveManager.Instance.SaveToolBarData(0);
        }
    }
}